/**
 * Created by Windows on 2016/1/11.
 */

$(function(){

    $(document).on('click', '.overlay-close', function() {
        $(".remove").addClass("dn");
    });

    $(document).on('click', '.delete-supply', function() {
        $(this).parents("li").remove();
    });

    $(".product .product_iwrap .operate").on("click",function(){
        var product_id = $(this).attr('product_id');
        var product_name = $(this).attr('product_name');
        var brand_name = $(this).attr('brand_name');
        var currency_id = $(this).attr('currency_id');
        if(currency_id=='2'){
            var valuePrefix = "$";
        }else{
            var valuePrefix = "￥";
        }
        $(".remove").removeClass("dn");
        $.ajax({
            url:"/json/getPricetrend",
            data:{product_id:product_id,currency_id:currency_id},
            type:"post",
            dataType:"json",
            success:function(data){
                var price = data.price;
                var create_time = data.create_time;
                $('#container').highcharts({
                    title: {
                        text: '塑料交易网产品价格走势',
                        x: -20 //center
                    },
                    subtitle: {
                        text: '来源: www.suliaojiaoyi.com',
                        x: -20
                    },
                    xAxis: {
                        categories: create_time
                    },
                    yAxis: {
                        title: {
                            text: '价格'
                        },
                        plotLines: [{
                            value: 0,
                            width: 1,
                            color: '#808080'
                        }]
                    },
                    tooltip: {
                        valuePrefix: valuePrefix
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'right',
                        verticalAlign: 'middle',
                        borderWidth: 0
                    },
                    series: [{
                        name: product_name+brand_name,
                        data:price
                    }]
                });
            }
        });


    });
});